import 'package:flutter/material.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:gw_github_flutter/common/route_name.dart';

class ChipRoute extends StatefulWidget {
  ChipRoute({Key? key}) : super(key: key);

  @override
  State<ChipRoute> createState() => _ChipRouteState();
}

class _ChipRouteState extends State<ChipRoute> {
  List<String> languages = <String>[
    'Flutter',
    'Android',
    'iOS',
    'Java',
    'Object-C',
    'JavaScript',
    'Ruby',
    'PHP',
    'C++',
    'C#',
    'C语言',
    'Dart',
    'Kotlin',
    'Swift'
  ];

  String _selectedMaterial = '';

  List<String> _actions = [];

  List<String> _selected = [];

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    _actions.addAll(languages);
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(RouteName.chipRoute),
      ),
      body: _body(),
    );
  }

  Widget _body() {
    return SingleChildScrollView(
      child: Column(
        mainAxisAlignment: MainAxisAlignment.center,
        children: [
          const Divider(),
          const Text('可删除Chip'),
          Wrap(
              spacing: 10.0,
              children: languages
                  .map((language) => Chip(
                      backgroundColor: Colors.lightBlue,
                      label: Text(language.toString(),
                          style: const TextStyle(color: Colors.white)),
                      onDeleted: () =>
                          setState(() => languages.remove(language))))
                  .toList()),
          const Divider(),
          const Text('单选ChoiceChip'),
          Wrap(
              spacing: 10.0,
              children: languages
                  .map((language) => ChoiceChip(
                      selected: _selectedMaterial == language,
                      backgroundColor: Colors.grey,
                      label: Text(language.toString(),
                          style: TextStyle(color: Colors.white)),
                      selectedColor: Colors.lightGreen,
                      onSelected: (bool isCheck) => setState(
                          () => _selectedMaterial = isCheck ? language : "")))
                  .toList()),
          const Divider(),
          const Text('混合InputChip'),
          Wrap(
              spacing: 10.0,
              children: languages
                  .map((language) => InputChip(
                      label: Text(language.toString(),
                          style: TextStyle(color: Colors.white)),
                      avatar: Image.asset("imgs/avatar-default.png"),
                      onPressed: () {},
                      backgroundColor: Colors.yellow))
                  .toList()),
          const Divider(),
          const Text('多选带对号FilterChip'),
          Wrap(
              spacing: 10.0,
              children: languages
                  .map((language) => FilterChip(
                      backgroundColor: const Color.fromARGB(255, 106, 186, 49),
                      label: Text(language),
                      selected: _selected.contains(language),
                      onSelected: (isSelected) => setState(() {
                            if (_selected.contains(language)) {
                              _selected.remove(language);
                            } else {
                              _selected.add(language);
                            }
                          }),
                      selectedColor: Colors.yellow))
                  .toList()),
          const Divider(),
          const Text('ActionChip'),
          Wrap(
              spacing: 10.0,
              children: languages
                  .map((language) => ActionChip(
                      backgroundColor: const Color.fromARGB(255, 233, 30, 182),
                      label: Text(language),
                      onPressed: () => EasyLoading.showToast(language)))
                  .toList()),
          const Divider(),
        ],
      ),
    );
  }
}
